package com.spring.processor;

import com.spring.service.BeanService2;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.lang.Nullable;
import org.springframework.stereotype.Component;

@Component
public class BeanPostProcessorExt implements BeanPostProcessor {

    @Nullable
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        if(beanName.equals("beanService2")){
            BeanService2 service2 = (BeanService2) bean;
            service2.print("before");
        }
        return bean;
    }

    @Nullable
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        if(beanName.equals("beanService2")){
            BeanService2 service2 = (BeanService2) bean;
            service2.print("after");
        }        return bean;
    }
}
